#!/bin/bash
target="$1"
shift
ip_re='([0-9]{1,3}\.){3}[0-9]{1,3}'
addr_re='Address: ([0-9.]+)'
if ! [[ $target =~ $ip_re ]]; then
    if [[ ! $(nslookup "$target") =~ $addr_re ]]; then
       echo "Could not find IP address $target" >&2
       exit 1
    fi
    echo "${BASH_REMATCH[1]}"
else
    echo "$target"
fi